package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.pojo.Category;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：qcq
 * @date ：Created in 2020/12/4 13:31
 * @description：
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public CategoryDTO queryCategoryById(Long id) {
        Category category = baseMapper.selectById(id);
        CategoryDTO categoryDTO = new CategoryDTO();
        categoryDTO.setId(category.getId());
        categoryDTO.setIsParent(category.getIsParent());
        categoryDTO.setName(category.getName());
        categoryDTO.setParentId(category.getParentId());
        categoryDTO.setSort(category.getSort());
        return categoryDTO;
    }

    @Override
    public List<CategoryDTO> queryCategoryByIdList(List<Long> ids) {
        List<Category> categories = this.listByIds(ids);
        List<CategoryDTO> categoryDTOList = CategoryDTO.convertEntityList(categories);
        return categoryDTOList;
    }

    @Override
    public List<CategoryDTO> queryCategoryByBrandId(Long id) {
        List<Category> categories = baseMapper.queryCategoryByBrandId(id);
        List<CategoryDTO> categoryDTOList = CategoryDTO.convertEntityList(categories);
        return categoryDTOList;
    }

    @Override
    public List<CategoryDTO> queryCategoryByParentId(Long id) {
        List<Category> categories = query().eq("parent_id", id).list();
        List<CategoryDTO> categoryDTOList = CategoryDTO.convertEntityList(categories);
        return categoryDTOList;
    }
}
